<template>
	<view class="b_width">
		
		<view class="info_box">
		<!-- 	<view class="upload_box">
				<u-upload @afterRead="afterRead" :previewImage='false' :previewFullImage="true">
					<view>
						<image :src="user.aimage" class='head_img' ></image>
						<view class="p_box b_flex_cc">
							<image class="phone" mode="widthFix" src="@/static/imgs/phone.png"></image>
						</view>
					</view>

				</u-upload>
			</view> -->
			
			<view class="input_box border_bottom">
				<view class="name">修改密码</view>
				<input class="val" placeholder-style="color:#9296AF" placeholder="请输入密码"
					v-model="form.password">
			</view>
			
			</view>
			<view class="submit_box" @click="submit()">确定</view>
			<view class="submit_box" @click="logout()">退出登录</view>
		</view>
	</view>
</template>

<script>
	import {
		setPassword
	} from "@/require/api.js";
	export default {
		data() {
			return {
				form:{password:''},
			}
		},
		onShow() {
			
		},
		methods: {
			submit(){
				let _ = this;
				uni.showModal({
					title: '确定要修改密码吗?',
					success(res) {
						if (res.confirm) {
							   _.set();
								
						}
					}
				})
			},
			async set() {
				let {
					data,
					msg,
					code
				} = await setPassword(this.form);
				if(code==1){
					this.$project.toast(msg);
					
					setTimeout(()=>{
						uni.removeStorageSync('ygzcToken');
						this.$project.toPaths('/pages/index/index'); 
					},1000);
					
					
				}
				
			},
			openImg() {
				uni.previewImage({
					urls: this.user.file
				});
			},
			logout() {
				let _ = this;
				uni.showModal({
					title: '确定要退出登录吗?',
					success(res) {
						if (res.confirm) {
								uni.removeStorageSync('ygzcToken');
								_.$project.toPaths('/pages/index/index'); 
						}
					}
				})
			},
			async setNickname() {
				let {
					data,
					msg
				} = await userEdit({
					nickname: this.user.nickname
				});
				this.$project.toast(msg);
				this.getUserInfo();
			},
			async afterRead(event) {
				let _=this;
				uni.cropImage({
					src:event.file.url,
					sropScale:'1:1',
					success(e){
					   _.uploadImg(e);
					},
					fail(e){
						console.log(e);
					}
				});
			},
			async uploadImg(e){
				const data = JSON.parse(await uploadFile(e.tempFilePath));
				let {
					msg
				} = await userEdit({
					aimage: data.data.url,
				});
				await this.getUserInfo();
				this.$project.toast(msg); 
			}
			
		}
	}
</script>

<style lang="scss" scoped>
	::v-deep .u-navbar__content__title {
		font-weight: 500;
		font-size: 34rpx !important;
		
	}
	.info_box {
		box-sizing: border-box;
		padding: 20rpx 20rpx
	}

	.upload_box {
		width: 180rpx;
		margin: 0 auto;
	}

	.head_img {
		width: 180rpx;
		height: 180rpx;
		border-radius: 50%;
	}

	.p_box {
		width: 50rpx;
		height: 50rpx;
		background-color: #fff;
		border-radius: 50%;
		margin-left: auto;
		position: relative;
		top: -65rpx;

	}

	.phone {
		width: 30rpx;
	}

	.input_box {
		box-sizing: border-box;
		padding: 10rpx 0 10rpx 0;
	}

	.border_bottom {
		border-bottom: 1rpx solid #F5F5F5;
	}

	.name {
		color: #252B50;
	}

	.val {
		color: #9296AF;
		font-size: 28rpx;
		margin-top: 20rpx;
	}
	.jg_icon{
		width: 11rpx;
		height: 19rpx;
		margin-left: 10rpx;
	}
	.sm{
		
		font-weight: 500;
		font-size: 26rpx;
		color: #FF4E1B;
		
	}
	.submit_box{
		background-color: #388FFF;
		text-align: center;
		width: 90%;
		
		color: #fff;
		border-radius: 35rpx;
		height: 80rpx;
		line-height: 80rpx;
		margin: 30rpx auto 0rpx auto;
	}
	.sf_box{
		margin-top: 15rpx;
	}
	.sf_img{
		width: 150rpx;
		height: 150rpx;
		margin-right: 10rpx;
	}
</style>